﻿using System;
using System.Collections.Generic;
using System.Text;
using com.lover.astd.common.logic;
using com.lover.astd.common.model;

namespace com.lover.astd.common.logicexe.equip
{
    public class PolishExe : ExeBase
    {
        public PolishExe() { _name = ConfigStrings.S_Polish; _readable = ConfigStrings.SR_Polish; }
        public override long execute()
        {
            if (_user.Level < 101) return next_day();
            Dictionary<string, string> conf = getConfig();
            if (conf.ContainsKey(ConfigStrings.enabled) && conf[ConfigStrings.enabled].ToLower().Equals("true"))
            {
                int reserve_count = 5, reserve_item_count = 5, gold_merge_attrib = 10, melt_failcount = 2;
                if (conf.ContainsKey(ConfigStrings.reserve_count)) Int32.TryParse(conf[ConfigStrings.reserve_count], out reserve_count);
                if (conf.ContainsKey(ConfigStrings.reserve_item_count)) Int32.TryParse(conf[ConfigStrings.reserve_item_count], out reserve_item_count);
                if (conf.ContainsKey(ConfigStrings.melt_failcount)) Int32.TryParse(conf[ConfigStrings.melt_failcount], out melt_failcount);
                if (conf.ContainsKey(ConfigStrings.gold_merge_attrib)) Int32.TryParse(conf[ConfigStrings.gold_merge_attrib], out gold_merge_attrib);

                int result = ServiceFactory.getEquipManager().handlePolishInfo(_proto, _logger, getGoldAvailable(), _user.Magic,
                    reserve_count, reserve_item_count, gold_merge_attrib, melt_failcount);
                if (result == 3) return next_hour();
                else if (result == 4) return immediate();
                return next_hour();
            }
            return next_halfhour();
        }
    }
}
